package com.st.event.demo.proxy.bean;

import com.st.event.demo.proxy.factory.EventProxyFactory;
import org.springframework.beans.factory.FactoryBean;

public class EventProviderFactoryBean<T> extends EventProviderBeanSupport implements FactoryBean<T> {

    private Class<T> clientInterface;

    public EventProviderFactoryBean(Class<T> clientInterface) {
        this.clientInterface = clientInterface;
    }

    public EventProviderFactoryBean() {
    }

    @Override
    public T getObject() throws Exception {
        return registerClient();
    }

    @Override
    public Class<?> getObjectType() {
        return this.clientInterface;
    }

    @Override
    public boolean isSingleton() {
        return true;
    }

    private T registerClient() {
        System.out.println("执行1-----------");
        EventProxyFactory<T> proxyFactory = new EventProxyFactory<>(this.clientInterface);
        return proxyFactory.newInstance(getEventAttributeSource(), getEventStrategy(), getListenerMap());
    }
}
